<template>
  <base-breadcrumb :title="$route.meta.title">
    <!-- 展示区样板实施申请 -->
    <div id="base-breadcrumb" style="position: relative; overflow: hidden">
      <!-- 搜索 -->
      <searchData :searchData="searchArr" @search="search"></searchData>
      <!-- 表格 -->
      <a-card :bordered="false">
        <!-- <title-name :title="$route.meta.title"></title-name> -->
        <a-button v-btnPermission="'qm_012_add_01'" class="mb12" icon="plus" type="primary" @click="handleManage(2)">添加申请</a-button>
        <!-- 统计汇总 -->
        <AuditSummary :form="queryParam" :loadCount="loadCount" :api="api" />
        <!-- 表格 -->
        <list-table
          ref="table"
          tableLayout="fixed"
          size="default"
          :rowKey="(record) => record.id"
          :columns="columns"
          :request="loadData"
          :alert="true"
          show-size-changer
          show-quick-jumper
          showPagination="auto"
        >
          <span slot="action" slot-scope="text, record">
            <MoreButton>
              <a v-btnPermission="'qm_012_loo_04'" @click="handleManage(0, record)">查看</a>
              <template v-if="record.isOperation && (record.statusCode === '0' || record.statusCode === '3')">
                <a-divider v-btnPermission="'qm_012_edi_02'" type="vertical"></a-divider>
                <a v-btnPermission="'qm_012_edi_02'" @click="handleManage(1, record)">编辑</a>
              </template>
              <!-- 删除 -->
              <template v-if="record.isOperation && record.statusCode === '0'">
                <a-divider v-btnPermission="'qm_012_del_03'" type="vertical"></a-divider>
                <a v-btnPermission="'qm_012_del_03'" @click="handleRemove(record.id)">删除</a>
              </template>
              <!-- 当状态为审批中 -->
              <template v-if="record.statusCode != '0'">
                <a-divider v-btnPermission="'qm_012_exa_05'" type="vertical"></a-divider>
                <a v-btnPermission="'qm_012_exa_05'" @click="$bus.$emit('showApprovalDetailsDialog', record.id)">审批详情</a>
              </template>
            </MoreButton>
          </span>
          <!-- 状态 -->
          <template slot="statusCode" slot-scope="text, record">
            <status-display :statusCode="record.statusCode" isApproval></status-display>
          </template>
          <template slot="expandedRowRender" slot-scope="text">
            样板制作原因说明：{{ text.makeReason || '暂无' }}
          </template>
        </list-table>
      </a-card>
    </div>
  </base-breadcrumb>
</template>

<script>
import { STable } from '@/components' // 表格
import { projectShowApply } from '@/api/quality/sample' // api
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目名称
import OrgTreeSelect from '@/components/OrgTreeSelect'
import StatusDisplay from '@/components/StatusDisplay'
import AuditSummary from '@/views/quality/components/AuditSummary' // 统计汇总
import SelectProjectStatus from '@/views/quality/components/SelectProjectStatus' // 项目状态

const searchArr = [
  // 搜索框
  {
    name: '所属单位',
    valueKey: 'searchQuery',
    type: OrgTreeSelect,
  },
  // {
  //   name: '分公司',
  //   type: SelectSubCompany,
  //   valueKey: 'branchCompanyId',
  // },
  // {
  //   name: '项目名称',
  //   type: SelectProject,
  //   valueKey: 'projectId',
  // },
  {
    name: '项目状态',
    type: SelectProjectStatus,
    valueKey: 'projectStatus'
  },
  // {
  //   name: '劳务单位',
  //   type: 'input',
  //   value: 'subcontractor',
  // },
]
const columns = [
  {
    title: '分公司',
    ellipsis: true,
    dataIndex: 'branchCompanyName',
  },
  {
    title: '项目',
    ellipsis: true,
    dataIndex: 'projectName',
  },
  {
    title: '拟制作的样板种类及数量',
    ellipsis: true,
    dataIndex: 'species',
  },
  // {
  //   title: '制作时间',
  //   ellipsis: true,
  //   dataIndex: 'makeDate',
  // },
  // {
  //   title: '劳务单位',
  //   ellipsis: true,
  //   dataIndex: 'subcontractor',
  // },
  {
    title: '状态',
    dataIndex: 'statusCode',
    scopedSlots: { customRender: 'statusCode' },
  },
  {
    title: '操作',
    dataIndex: 'action',
    width: '180px',
    align: 'center',
    scopedSlots: { customRender: 'action' },
  },
]
export default {
  name:'a'+ Date.now(),
  components: {
    STable,
    StatusDisplay,
    AuditSummary,
  },
  data() {
    this.columns = columns
    this.searchArr = searchArr
    return {
      // 查询参数
      queryParam: {},
      // 盒子高度
      boxHeight: 0,
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        return projectShowApply.postList(requestParameters).then((res) => {
          return res
        })
      },
      api: projectShowApply, // api
      loadCount: 0, // 汇总加载控件
      editModel: 0,
      form: {},
    }
  },
  methods: {
    /**
     * 删除草稿
     */
    handleRemove(id) {
      this.$confirm({
        title: '温馨提示',
        content: '确定删除草稿？',
        onOk: () => {
          return projectShowApply.remove({ id: id }).then((res) => {
            this.$message.success('删除成功！')
            // 关闭当前页
            this.search()
          })
          // .catch((res) => {
          //   this.$message.warning('删除失败！')
          // })
        },
      })
    },
    // 搜索
    search(value) {
      value && (this.queryParam = value)
      this.$refs.table.refresh(true)
      this.loadCount++
    },
    // 操作栏
    handleManage(type, record) {
      this.editModel = type
      let query = {
        editModel: type,
      }
      if (record && record.id) {
        query.id = record.id
      }
      this.$router.push({
        name: '/quality/modelProject/exhibitionAreaApplication/exhibitionAreaApplicationEdit',
        query,
      })
    },
  },
}
</script>
